﻿// Example header text. Can be configured in the options.
using System;
using System.Data;
using vtech_formBase;
using vtech_frameWorks.Exceptions;

namespace vtech_system.Role
{
    public partial class frmAddRole : frmAdd
    {
        #region Delegate
        public delegate void Add();
        public event Add OnAdd = null;
        protected override void FireEvent()
        {
            if (this.OnAdd != null)
            {
                this.OnAdd();
            }
        }

        #endregion

        public frmAddRole()
        {
            this.InitializeComponent();
        }

        protected override bool CheckControl()
        {
            bool flag = true;
            try
            {
                this.errorProvider.Dispose();
                if (this.txtCode.Text == "")
                {
                    this.errorProvider.SetError(this.txtCode, "Bạn chưa nhập mã quyền. Xin vui lòng kiểm tra lại");
                    flag = false;
                }
                else
                {
                    if (this.txtName.Text == "")
                    {
                        this.errorProvider.SetError(this.txtName, "Bạn chưa nhập tên quyền. Xin vui lòng kiểm tra lại");
                        flag = false;
                    }
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                flag = false;
            }
            return flag;
        }

        protected override void Insert()
        {
            try
            {
                using (DsRole dsRole = new DsRole())
                {
                    ClsRoleBS obj = new ClsRoleBS();
                    DataRow drow = dsRole.DtRole.NewRow();
                    dsRole.DtRole.Rows.Add(drow);
                    drow["ID"] = Guid.NewGuid();
                    drow["Code"] = this.txtCode.Text;
                    drow["Name"] = this.txtName.Text;
                    drow["Description"] = this.txtDescription.Text;
                    drow["Inactive"] = 0;
                    obj.DoInsert(dsRole.DtRole);
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.ToString());
            }
        }
    }
}